import requests
from config.config import *
import  time
import os

#  测试报告地址
if os.environ["ENV"] == "prod":
    REPORT_PATH = "http://192.168.10.171:8080/job/jkzdh_erp_git_prod/allure/"
elif os.environ["ENV"] == "test":
    REPORT_PATH = ""
def send_feishu_message():
    # 构造富文本消息
    message_data = [
        [{
            "tag": "text",
            "text": f"项目名称:{PROJECT}",
        }],
        [{
            "tag": "text",
            "text": f"执行时间:{time.strftime('%Y-%m-%d %H:%M:%S')}"
        }],
        [{
            "tag": "text",
            "text": "详细信息:"
        }, {
            "tag": "a",
            "text": "查看测试报告",
            "href": REPORT_PATH
        }]
    ]
    # 构造最终的消息体
    payload ={
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": "自动化测试报告",
                    "content": message_data
                }
            }
        }
    }
    #判断是否发送
    if FEISHU_IS_SEND:
        response = requests.post(WEBHOOK,json=payload)
        return response

if __name__ == '__main__':
    send_feishu_message()

